from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-05 14:12:15.074802
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 05, Sep, 2021
Time: 14:12:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9989
Nobs: 405.000 HQIC: -46.5365
Log likelihood: 4412.93 FPE: 4.33049e-21
AIC: -46.8887 Det(Omega_mle): 3.47696e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.430360 0.094099 4.573 0.000
L1.Burgenland 0.104308 0.048566 2.148 0.032
L1.Kärnten -0.114492 0.024170 -4.737 0.000
L1.Niederösterreich 0.171145 0.104927 1.631 0.103
L1.Oberösterreich 0.122699 0.102200 1.201 0.230
L1.Salzburg 0.282919 0.050948 5.553 0.000
L1.Steiermark 0.021911 0.067475 0.325 0.745
L1.Tirol 0.109214 0.053381 2.046 0.041
L1.Vorarlberg -0.111811 0.048069 -2.326 0.020
L1.Wien -0.008986 0.092893 -0.097 0.923
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013634 0.218238 0.062 0.950
L1.Burgenland -0.046050 0.112636 -0.409 0.683
L1.Kärnten 0.037712 0.056055 0.673 0.501
L1.Niederösterreich -0.199789 0.243352 -0.821 0.412
L1.Oberösterreich 0.488278 0.237026 2.060 0.039
L1.Salzburg 0.304827 0.118161 2.580 0.010
L1.Steiermark 0.109515 0.156491 0.700 0.484
L1.Tirol 0.314948 0.123804 2.544 0.011
L1.Vorarlberg -0.000834 0.111483 -0.007 0.994
L1.Wien -0.010721 0.215442 -0.050 0.960
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.255494 0.047713 5.355 0.000
L1.Burgenland 0.088901 0.024626 3.610 0.000
L1.Kärnten -0.002787 0.012255 -0.227 0.820
L1.Niederösterreich 0.206705 0.053204 3.885 0.000
L1.Oberösterreich 0.168257 0.051821 3.247 0.001
L1.Salzburg 0.035284 0.025834 1.366 0.172
L1.Steiermark 0.019270 0.034214 0.563 0.573
L1.Tirol 0.063300 0.027067 2.339 0.019
L1.Vorarlberg 0.059191 0.024373 2.428 0.015
L1.Wien 0.107663 0.047102 2.286 0.022
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181035 0.046853 3.864 0.000
L1.Burgenland 0.047702 0.024182 1.973 0.049
L1.Kärnten -0.006701 0.012034 -0.557 0.578
L1.Niederösterreich 0.139352 0.052244 2.667 0.008
L1.Oberösterreich 0.317179 0.050886 6.233 0.000
L1.Salzburg 0.099795 0.025368 3.934 0.000
L1.Steiermark 0.131440 0.033596 3.912 0.000
L1.Tirol 0.076123 0.026579 2.864 0.004
L1.Vorarlberg 0.056216 0.023934 2.349 0.019
L1.Wien -0.042524 0.046252 -0.919 0.358
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208638 0.093200 2.239 0.025
L1.Burgenland -0.056632 0.048102 -1.177 0.239
L1.Kärnten -0.034201 0.023939 -1.429 0.153
L1.Niederösterreich 0.118528 0.103925 1.141 0.254
L1.Oberösterreich 0.164747 0.101223 1.628 0.104
L1.Salzburg 0.257538 0.050461 5.104 0.000
L1.Steiermark 0.081168 0.066830 1.215 0.225
L1.Tirol 0.121656 0.052871 2.301 0.021
L1.Vorarlberg 0.117327 0.047609 2.464 0.014
L1.Wien 0.025644 0.092006 0.279 0.780
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026970 0.072362 0.373 0.709
L1.Burgenland 0.024867 0.037347 0.666 0.506
L1.Kärnten 0.052001 0.018587 2.798 0.005
L1.Niederösterreich 0.209813 0.080689 2.600 0.009
L1.Oberösterreich 0.336380 0.078592 4.280 0.000
L1.Salzburg 0.044923 0.039179 1.147 0.252
L1.Steiermark -0.004006 0.051889 -0.077 0.938
L1.Tirol 0.113362 0.041050 2.762 0.006
L1.Vorarlberg 0.065672 0.036965 1.777 0.076
L1.Wien 0.130863 0.071435 1.832 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189261 0.088458 2.140 0.032
L1.Burgenland 0.020557 0.045655 0.450 0.653
L1.Kärnten -0.057948 0.022721 -2.550 0.011
L1.Niederösterreich -0.114737 0.098637 -1.163 0.245
L1.Oberösterreich 0.188333 0.096074 1.960 0.050
L1.Salzburg 0.027699 0.047894 0.578 0.563
L1.Steiermark 0.300158 0.063430 4.732 0.000
L1.Tirol 0.489308 0.050181 9.751 0.000
L1.Vorarlberg 0.070662 0.045187 1.564 0.118
L1.Wien -0.110388 0.087325 -1.264 0.206
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155457 0.096082 1.618 0.106
L1.Burgenland -0.006006 0.049590 -0.121 0.904
L1.Kärnten 0.062585 0.024679 2.536 0.011
L1.Niederösterreich 0.200042 0.107139 1.867 0.062
L1.Oberösterreich -0.125503 0.104354 -1.203 0.229
L1.Salzburg 0.236438 0.052022 4.545 0.000
L1.Steiermark 0.155598 0.068897 2.258 0.024
L1.Tirol 0.049506 0.054506 0.908 0.364
L1.Vorarlberg 0.124775 0.049082 2.542 0.011
L1.Wien 0.149947 0.094851 1.581 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488024 0.052114 9.364 0.000
L1.Burgenland -0.010461 0.026897 -0.389 0.697
L1.Kärnten -0.010114 0.013386 -0.756 0.450
L1.Niederösterreich 0.208993 0.058111 3.596 0.000
L1.Oberösterreich 0.255452 0.056601 4.513 0.000
L1.Salzburg 0.023993 0.028216 0.850 0.395
L1.Steiermark -0.025728 0.037369 -0.688 0.491
L1.Tirol 0.070285 0.029564 2.377 0.017
L1.Vorarlberg 0.058373 0.026622 2.193 0.028
L1.Wien -0.055801 0.051447 -1.085 0.278
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019783 0.077608 0.135713 0.135651 0.040904 0.071148 -0.001293 0.175704
Kärnten 0.019783 1.000000 -0.045297 0.126489 0.047560 0.069509 0.456593 -0.094266 0.092318
Niederösterreich 0.077608 -0.045297 1.000000 0.285101 0.085462 0.272334 0.025085 0.145752 0.254338
Oberösterreich 0.135713 0.126489 0.285101 1.000000 0.184349 0.286284 0.158276 0.103975 0.138210
Salzburg 0.135651 0.047560 0.085462 0.184349 1.000000 0.127862 0.060273 0.103609 0.052163
Steiermark 0.040904 0.069509 0.272334 0.286284 0.127862 1.000000 0.130244 0.087584 -0.025810
Tirol 0.071148 0.456593 0.025085 0.158276 0.060273 0.130244 1.000000 0.040665 0.119224
Vorarlberg -0.001293 -0.094266 0.145752 0.103975 0.103609 0.087584 0.040665 1.000000 -0.048688
Wien 0.175704 0.092318 0.254338 0.138210 0.052163 -0.025810 0.119224 -0.048688 1.000000